package com.diqizu.dao;

/**
 *   Ʒҳ  
 * @author       
 *
 */
import java.sql.ResultSet;

import java.sql.SQLException;
import java.util.ArrayList;
import com.diqizu.entity.ChanPininof;
import com.diqizu.entity.LunBo;
import com.diqizu.utli.DBManager;
import com.diqizu.utli.QueryDataResult;

public class ChanPinDaoImpl {
  public ArrayList<ChanPininof> getALlcp() {

    String sql = "select * from chanpininfo where zhanshi = '是' ";
    System.out.println("     sql     " + sql);
    QueryDataResult execQuery = DBManager.execQuery(sql);
    ArrayList<ChanPininof> list = new ArrayList<ChanPininof>();
    if (execQuery != null) {
      ResultSet rs = execQuery.rs;
      try {
        while (rs.next()) {
          ChanPininof e = new ChanPininof();
          e.setId(rs.getInt(1));
          e.setColor(rs.getString(2));
          e.setName(rs.getString(3));
          e.setStyle(rs.getString(4));
          e.setImga(rs.getString(5));
          e.setZhanshi(rs.getString(6));
          list.add(e);
        }
      } catch (SQLException e) {
        e.printStackTrace();
      } finally {
        execQuery.close();
      }
    }
    System.out.println(list);
    return list;
  }
  public ArrayList<ChanPininof> getALlcp2() {
    String sql = "select * from chanpininfo";
    System.out.println("     sql     " + sql);
    QueryDataResult execQuery = DBManager.execQuery(sql);
    ArrayList<ChanPininof> list = new ArrayList<ChanPininof>();
    if (execQuery != null) {
      ResultSet rs = execQuery.rs;
      try {
        while (rs.next()) {
          ChanPininof e = new ChanPininof();
          e.setId(rs.getInt(1));
          e.setColor(rs.getString(2));
          e.setName(rs.getString(3));
          e.setStyle(rs.getString(4));
          e.setImga(rs.getString(5));
          list.add(e);
        }
      } catch (SQLException e) {
        e.printStackTrace();
      } finally {
        execQuery.close();
      }
    }
    System.out.println(list);
    return list;
  }
  public  boolean getALllb6(ChanPininof CP) {
    String sql ="insert into chanpininfo (name,style,color,imga,zhanshi) values('"+CP.getName()+"','"+CP.getStyle()+"','"+CP.getColor()+"','"+CP.getImga()+"','"+CP.getZhanshi()+"')";
    System.out.println("ִ查询的语句是:" + sql);
    return DBManager.execUpdate(sql);
  
  }
  public  boolean getALllb7(ChanPininof CP) {
    String sql = "update chanpininfo set name='" + CP.getName() + "',style='" + CP.getStyle() + "',color='"
        + CP.getColor() + "',imga='" +CP.getImga() + "',zhanshi='" + CP.getZhanshi() + "'where id="+CP.getId();
    System.out.println("ִ查询的语句是:" + sql);
    return DBManager.execUpdate(sql);
  
  }
  public  boolean getALllb8(int id) {
    String sql ="delete from chanpininfo where id="+id;
    System.out.println("ִ查询的语句是:" + sql);
    return DBManager.execUpdate(sql);
  
  }
}